package com.guigu.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.guigu.dao.OrderMapper;
import com.guigu.entity.PageResult;
import com.guigu.pojo.Member;
import com.guigu.pojo.Order;
import com.guigu.pojo.Setmeal;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Kc
 * @date 2021-04-21
 */
@Service(interfaceClass = OrderService.class)
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    /**
     * queryAllOrder
     * 查询预约列表
     * @param currentPage
     * @param pageSize
     * @param queryString
     * @return
     */
    @Override
    public PageResult queryAllOrder(Integer currentPage, Integer pageSize, String queryString,String queryStatus){
        PageHelper.startPage(currentPage,pageSize);
        Page<Order> orders = orderMapper.queryAllOrder(queryString,queryStatus);
        return new PageResult(orders.getTotal(),orders.getResult());
    }

    /**
     * 根据id修改 已经预约的状态为 预约成功
     *
     * @param id
     * @return
     */
    @Override
    public boolean updateById(Integer id) {
        int i = orderMapper.updateById(id);
        if(i>0){
            return true;
        }
        return false;
    }

    /**
     * updateById2
     *
     * @param id
     * @return
     */
    @Override
    public boolean updateById2(Integer id) {
        int i = orderMapper.updateById2(id);
        if(i>0){
            return true;
        }
        return false;
    }

    /**
     * 查询全部有用的会员
     * queryAllMember
     *
     * @return
     */
    @Override
    public List<Member> queryAllMember() {
        List<Member> members = orderMapper.queryAllMember();
        return members;
    }

    /**
     * 查询所有的套餐名称
     * @return
     */
    @Override
    public List<Setmeal> queryAllSetmeal() {
        List<Setmeal> setmeals = orderMapper.queryAllSetmeal();
        return setmeals;
    }

    /**
     * 添加用户
     *
     * @param order
     * @return
     */
    @Override
    public boolean add(Order order) {
        int add = orderMapper.add(order);
        if(add>0){
            return true;
        }
        return false;
    }
}
